package com.lul15834.orderfood.activity.user.adapter;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.lul15834.orderfood.R;
import com.lul15834.orderfood.activity.user.UpdateAddress;
import com.lul15834.orderfood.bean.AddressBean;

import java.util.List;

/**
 * 显示商家商品的adapter
 */
public class UserAddressAdapter extends RecyclerView.Adapter<UserAddressAdapter.AddressViewHolder> {
    private List<AddressBean> list;
    public UserAddressAdapter( List<AddressBean> list){
        this.list=list;

    }


    @NonNull
    @Override
    public UserAddressAdapter.AddressViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater inflater=LayoutInflater.from(parent.getContext());
        View convertView=inflater.inflate(R.layout.list_user_manage_address,parent,false);

        return new AddressViewHolder(convertView);
    }

    @Override
    public void onBindViewHolder(@NonNull UserAddressAdapter.AddressViewHolder holder, int position) {
        AddressBean tem=list.get(position);
        holder.name.setText(tem.getsUserName());
        holder.address.setText(tem.getsUserAddress());
        holder.phone.setText(tem.getsUserPhone());
        //实现编辑功能
        holder.img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(holder.itemView.getContext(), UpdateAddress.class);
                intent.putExtra("address",tem);
                holder.itemView.getContext().startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    static class AddressViewHolder extends RecyclerView.ViewHolder{
        TextView name;
        TextView address;
        TextView phone;
        View itemView;
        ImageView img;
        public AddressViewHolder(@NonNull View itemView) {
            super(itemView);
            name=itemView.findViewById(R.id.list_user_manage_address_name);
            address=itemView.findViewById(R.id.list_user_manage_address);
            phone=itemView.findViewById(R.id.list_user_manage_address_phone);
            img=itemView.findViewById(R.id.list_user_manage_address_img);
            this.itemView=itemView;
        }
    }


}

